#include "unit_tool.h"
#include "data_manager.h"

#include <QApplication>
#include <QByteArray>
#include <QDebug>
#include <QWidget>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    DataManager dataManager;

    auto data = QByteArray::fromHex("7E000101020000000000E900000000313233343536EC7E");
    qWarning() << "src     :" << data.toHex();
    Msg msg = getMsg(data);
    qWarning() << msg;
    // 插入数据
    dataManager += data;

    // msg.genAskBody.askID = msg.msgHead.msgID;
    // msg.genAskBody.askNum = msg.msgHead.msgNum;
    // msg.genAskBody.result = 0;
    // msg.msgHead.version = 0;
    // msg.msgHead.msgID = GenAsk;
    // msg.msgHead.msgNum += 1;

    // QByteArray makeData = makeMsg(msg);
    // qWarning() << "makeData:" << makeData.toHex();

    // data = QByteArray::fromHex("7E000082040001000000E90000000000020000005200020000000000010002000A357E");
    // qWarning() << "src     :" << data.toHex();
    // msg = getMsg(data);
    // qWarning() << msg;
    // makeData = makeMsg(msg);
    // qWarning() << "makeData:" << makeData.toHex();

    data = QByteArray::fromHex("7E00010200000B000000E900000000000000060E534A840000001BC5FA76A5000021A045F69760004D0000000100000000000000000000000000000000000A00000000000000000000018CC7D00908000000001B020000500200165102000052020000530200005402000055020001560200005704000000005802000059040000000060020000610200006202000063010064040000000065010066020000670100680100690100700400000000740400000000750400000000E57E");
    qWarning() << "src     :" << data.toHex();
    msg = getMsg(data);
    qWarning() << msg;
    // 插入半截数据
    data = QByteArray::fromHex("7E00010200000B000000E900000000000000060E534A840000001BC5FA76A5000021A045F69760004D0000000100000000000000000000000000000000000A00000000000000000000018CC7D00908000000001B0200005002001651020000520200005302000054020000550200015602000057040000000058020000590400000000600200006102000062020000630100640400000000650100660200006701006801006901007004000000007404000000007504000000");
    dataManager += data;

    auto datas = dataManager.getDatas();
    for (int i = 0; i < datas.size(); i++) {
        msg = getMsg(datas[i]);
        qWarning() << msg;
    }
    // 插入剩余半截数据
    dataManager += QByteArray::fromHex("00E57E");
    datas = dataManager.getDatas();
    for (int i = 0; i < datas.size(); i++) {
        msg = getMsg(datas[i]);
        qWarning() << msg;
    }
    QWidget w;
    w.show();

    return a.exec();
}
